package com.example.shilehui;

import java.util.List;

import cn.jhc.Adapter.SelectProvincesAdapter;
import cn.jhc.bean.City;
import cn.jhc.bean.Province;
import cn.jhc.service.XMLPullService;
import cn.jhc.utils.ActivityForResultRequestCode;
import cn.jhc.utils.Strings;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ListView;

public class SelectProvincesActivity extends Activity {

	ListView selectProvincesListView;
	List<Province> provinces;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.select_provinces);
		
		try {
			provinces=XMLPullService.getProvince();
			selectProvincesListView=(ListView) findViewById(R.id.select_provinces_listview);
			SelectProvincesAdapter selectProvincesAdapter=new SelectProvincesAdapter(this,this,provinces);
			selectProvincesListView.setAdapter(selectProvincesAdapter);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if(requestCode==ActivityForResultRequestCode.SELECT_CITY && resultCode==ActivityForResultRequestCode.SELECT_CITY){
			if(data.getBooleanExtra(Strings.SELECT_FINISH, false)){
				Province province=(Province) data.getSerializableExtra(Strings.SELECT_PROVINCE);
				City city=(City) data.getSerializableExtra(Strings.SELECT_CITY);
				SetMyAccountActivity.userModifyInfo.setProvince(province.getProvinceName());
				SetMyAccountActivity.userModifyInfo.setCity(city.getCityName());
				SetMyAccountActivity.setMyAccountAdapter.notifyDataSetChanged();
				finish();
			}
			
		}
	}

	public void select_provinces_back(View v){
		finish();
	}
	
}
